<template>
    <div class="loanApplyDeal">
        <el-breadcrumb class="breadcrumb" separator="/">
            <el-breadcrumb-item :to="{ path: '/order' }">我的订单</el-breadcrumb-item>
            <el-breadcrumb-item>订单处理</el-breadcrumb-item>
        </el-breadcrumb>
        <div class="dialog-edit">
            <el-dialog size="large" title="贷款申请" :visible.sync="isEdit" top="80px">
                <hr>
                <el-tabs class="info-tabs" v-model="activeNameDialog" @tab-click="$libs.scrollTop('.el-tabs__content')">
                    <template v-for="vm in tapListDialog">
                        <el-tab-pane class="info-temp" :label="vm.name" :name="'tap'+vm.index">
                            <div :is="vm.temp" :ref="vm.temp + 'Dialog'"></div>
                        </el-tab-pane>
                    </template>
                </el-tabs>
                <div class="dialog-footer">
                    <el-button @click="saves" type="save">保存</el-button>
                    <el-button type="primary" @click="submit" :disabled="isTip==true || isFirstSubmit==false">提交</el-button>
                    <label v-show="isTip" class="tip">征信结果未录入无法进行提交！</label>
                    <label v-show="$store.state.isAllMust && isSubmit" class="tip">资料未填写完整无法进行提交！</label>
                </div>
            </el-dialog>
        </div>
        <div class="footer-content" v-show="isChange==0 && ($store.state.power=='ROLE_SALESMAN'||$store.state.power=='ROLE_SPSALESMAN')">
            <el-button v-show=" orderStatus==21" class="cancel" @click="recall">撤回</el-button>
            <el-button v-show="orderStatus==10||orderStatus==11||orderStatus==12||orderStatus==13 || orderStatus==21 || orderStatus==22 || orderStatus==23|| orderStatus==31 || orderStatus==32|| orderStatus==33 || orderStatus==43" class="cancel" @click="dialogVisibleVaild = true">作废处理</el-button>
            <el-button v-show="orderStatus==13||orderStatus==22 || orderStatus==32|| orderStatus==31|| orderStatus==33||orderStatus==23 " class="cancel" @click="change">修改</el-button>
            <el-button v-show="orderStatus==13" @click="modyfyApplyEnter" type="success toRight">修改申请</el-button>
            <el-button v-show="orderStatus==10 || orderStatus==11||orderStatus==23 || orderStatus==43" @click="loanApplyEnter" type="success toRight">贷款申请</el-button>
            <el-button v-show="orderStatus==22|| orderStatus==33" type="success toRight" @click="applyPlayMoney">打款申请</el-button>
            <el-button v-show="isTrShow==true" type="primary toRight" @click="loanApplyException">通融申请</el-button>
            <el-button v-show="orderStatus==21 || orderStatus==22|| orderStatus==23 || orderStatus==32|| orderStatus==31|| orderStatus==33" type="primary toRight" @click="infoAdd">补充资料</el-button>
            <el-button v-show="orderStatus==10||orderStatus==11||orderStatus==12 || orderStatus==43" class="cancel" @click="creditEdit">征信修改</el-button>
            <el-button v-show="isChangeLoanShow == true && (orderStatus==10||orderStatus==11||orderStatus==12||orderStatus==13|| orderStatus==23||isChange==1 || orderStatus==43)" class="cancel" @click="dialogVisibleLoan = true">互换主贷人</el-button>
        </div>
        <div class="footer-content" v-show="isChange!=0">
            <el-button class="el-button--save" @click="cancalInfo">取消</el-button>
            <el-button type="primary" @click="submitInfo" :disabled="isFirstSubmit2==false">提交</el-button>
        </div>
        <div class="info-content">
            <steps ref="steps"></steps>
            <el-tabs class="info-tabs" v-model="activeName" @tab-click="$libs.scrollTop('.el-tabs__content')">
                <template v-for="vm in tapList">
                    <el-tab-pane class="info-temp" :label="vm.name" :name="'tap'+vm.index">
                        <div v-if="vm.temp=='attachment'" :is="vm.temp" :ref="vm.temp" @submit-attachmentHad="attachHave"></div>
                        <div v-else :is="vm.temp" :ref="vm.temp"></div>
                    </el-tab-pane>
                </template>
            </el-tabs>
        </div>
        <el-dialog class="dialog" title="作废处理" :visible.sync="dialogVisibleVaild" size="tiny" :before-close="dialogLoanClose">
            <div class="dialogContent">
                <p>请选择作废原因</p>
                <div v-for="(vm,index) in invaildReason">
                    <el-radio class="radio" v-model="invalidRusult" :label="vm">{{vm}}</el-radio>
                </div>
            </div>
            <hr class="hrDefault">
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisibleVaild = false">取 消</el-button>
                <el-button type="primary"  @click="invalid">确 定</el-button>
            </span>
        </el-dialog>
        <el-dialog class="dialog" title="互换主贷人" :visible.sync="dialogVisibleLoan" size="tiny" :before-close="dialogLoanClose">
            <div class="dialogContent">
                <p>请输入调换原因</p>
                <el-input type="textarea" placeholder="请输入" v-model="changeLoanRusult"></el-input>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisibleLoan = false">取 消</el-button>
                <el-button type="primary"  @click="changeLoanMajorPerson">确 定</el-button>
            </span>
        </el-dialog>
        <el-dialog class="dialog-edit" size="large" title="补录资料" :visible.sync="supplementShow">
            <div class="gpsAddDialog">
                <div class="title">GPS信息</div>
                <el-row class="info-row">
                    <el-col :span="3" class="subTitle">
                        GPS编号
                    </el-col>
                    <el-col :span="5" class="info-label">
                        <el-input class="info-input" placeholder="请输入" v-model="GPSNumber"></el-input>
                    </el-col>
                    <el-col :span="3" :offset="1" class="subTitle">
                        安装位置
                    </el-col>
                    <el-col :span="5" class="info-label">
                        <el-input class="info-input" placeholder="请输入" v-model="GPSPlace"></el-input>
                    </el-col>
                </el-row>
                <el-row>
                    <attachment ref="attachmentAdd"></attachment>
                </el-row>
            </div>
            <div class="dialog-footer">
                <el-button type="primary" @click="supplementSave()">保存</el-button>
            </div>
        </el-dialog>
        <div class="dialog-edit">
            <el-dialog size="large" title="修改提交" :visible.sync="isChangeEdit" top="80px">
                <hr>
                <el-tabs class="info-tabs" v-model="activeNameChangeDialog" @tab-click="$libs.scrollTop('.el-tabs__content')">
                    <template v-for="vm in tapListChangeDialog">
                        <el-tab-pane class="info-temp" :label="vm.name" :name="'tap'+vm.index">
                            <div :is="vm.temp" :ref="vm.temp + 'ChangeDialog'"></div>
                        </el-tab-pane>
                    </template>
                </el-tabs>
                <div class="dialog-footer">
                    <el-button @click="savesChangeDialog" type="save">保存</el-button>
                    <el-button type="primary" @click="submitChangeDialog" :disabled=" isFirstSubmitChangeDialog==false">提交</el-button>
                    <label v-show="$store.state.isAllMust && isSubmitChangeDialog" class="tip">资料未填写完整无法进行提交！</label>
                </div>
            </el-dialog>
        </div>
    </div>
</template>
<script>
export default {
    name: 'loanApplyDeal',
    components: {
        steps: require('../../components/other/steps'),
        credit: require('../../components/order/credit'),
        customInfo: require('../../components/order/customInfo'),
        carBuyCommon: require('../../components/order/carBuyCommon'),
        carAndCredit: require('../../components/order/carAndCredit'),
        attachment: require('../../components/order/attachment'),
        assurePerson: require('../../components/order/assurePerson'),
        historyLoan: require('../../components/order/historyLoan'),
        checkInfo: require('../../components/order/checkInfo'),
    },
    data() {
        return {
            orderNo: this.$route.query.orderNo,
            annexBatchNo: this.$route.query.annexBatchNo,
            customerIdCard: this.$route.query.customerIdCard,
            orderStatus: this.$route.query.orderStatus,
            applyId: this.$route.query.applyId,
            activeName: 'tap0',
            activeNameDialog: 'tap1',
            isEdit: false,
            isTip: false,
            isSubmit: false,
            tapNumEdit: 0,
            isTrShow: false, //是否显示通融申请按钮
            isChangeLoanShow: true, //是否有互换主贷人按钮
            isChange: 0, //0 未修改 1修改资料 2修改征信
            isFirstSubmit: true, //贷款申请的提交
            isFirstSubmit2: true, //修改的提交
            isChangeEdit: false, //修改提交补充担保人和共同购车人的dialog
            activeNameChangeDialog: 'tap2',
            isSubmitChangeDialog: false,
            isFirstSubmitChangeDialog: true,
            tapListChangeDialog: [
                { name: '共同购车人', index: 2, temp: 'carBuyCommon', show: true },
                { name: '担保人', index: 3, temp: 'assurePerson', show: true },
            ],
            tapList: [
                { name: '征信结果', index: 0, temp: 'credit', show: true },
                { name: '客户信息', index: 1, temp: 'customInfo', show: true },
                { name: '共同购车人', index: 2, temp: 'carBuyCommon', show: true },
                { name: '担保人', index: 3, temp: 'assurePerson', show: true },
                { name: '车辆及贷款信息', index: 4, temp: 'carAndCredit', show: true },
                { name: '审核信息', index: 10, temp: 'checkInfo', show: true },
                { name: '附件', index: 5, temp: 'attachment', show: 'none' },
                { name: '历史贷款记录', index: 6, temp: 'historyLoan', show: true },
            ],
            tapListDialog: [
                { name: '客户信息', index: 1, temp: 'customInfo', show: true },
                { name: '共同购车人', index: 2, temp: 'carBuyCommon', show: true },
                { name: '担保人', index: 3, temp: 'assurePerson', show: true },
                { name: '车辆及贷款信息', index: 4, temp: 'carAndCredit', show: true },
                { name: '附件', index: 5, temp: 'attachment', show: true },
            ],
            dialogVisibleVaild: false, //作废处理弹出框状
            invaildReason: ['客户放弃贷款', '信息录错', '其他'],
            invalidRusult: '其他', //作废原因
            dialogVisibleLoan: false, //互换主贷人弹出框状态
            changeLoanRusult: '', //互换主贷人原因
            supplementShow: false, //补录资料
            GPSPlace: '',
            GPSNumber: '',
            isAttachHaveRun: false,
        }
    },
    watch: {
        tapNumEdit: function(_cur, _old) {
            console.log('tapNumEdit-' + _cur);
            if (_cur == 3) {
                console.log(this);
                for (var i = 0; i < this.tapList.length; i++) {
                    if (this.tapList[i].show == false) {
                        this.tapList.splice(i, 1);
                        i--;
                    }
                }
                this.tapNumEdit = 0;
                this.$nextTick(() => {
                    this.getDataSecond();
                    if (this.$route.query.isShowDialog == '1') {
                        this.loanApplyEnter();
                    }
                });
            }
        },
        deep: true
    },
    methods: {
        modyfyApplyEnter: function() {
            this.$confirm('是否确认发起修改申请?', '取消', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$http.post('/submitTaskController/updateApply', {
                    applyType: 4,
                    orderNo: this.orderNo,
                    remark: '修改申请'
                }).then((data) => {
                    if (data.data.success) {
                        this.$libs.successAlert(this, {
                            title: '修改申请提交成功！',
                            theme: '修改申请',
                            enter: '知道了',
                        });
                    }
                }).catch((error) => {

                });
            }).catch((error) => {});
        },
        infoAdd() {
            // 补充资料
            this.supplementShow = true;
            this.$nextTick(() => {
                this.GPSNumber = this.$refs.carAndCredit[0].gpsInfo.code;
                this.GPSPlace = this.$refs.carAndCredit[0].gpsInfo.gpsLocation;
                this.$refs.attachmentAdd.isEdit = true;
                this.$refs.attachmentAdd.postDeal(this.orderNo, this.annexBatchNo);
            });
        },
        supplementSave() {
            // 补录资料
            console.log(this.GPSPlace);
            let param = {
                "gpsNum": this.GPSNumber,
                "gpsSetLocation": this.GPSPlace,
                "orderNo": this.orderNo,
            };
            this.$http.post('/submitTaskController/collectionData', param).then((response) => {
                console.log(response);
                if (response.data.success) {
                    this.$message({
                        message: '保存成功！',
                        type: 'success'
                    });
                    this.supplementShow = false;
                } else {
                    this.$message.error('保存失败!');
                }
            }).catch((error) => {

            });
        },
        applyPlayMoney() {
            // 打款申请
            let param = {
                "applyType": "2",
                "bizType": "1",
                "orderNo": this.orderNo,
                "remark": "打款申请"
            };
            this.$confirm('是否确认发起打款申请?', '打款申请确认', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$http.post("/submitTaskController/salesManPayMentApply", param)
                    .then((response) => {
                        console.log(response);
                        if (response.data.success) {
                            if (response.data.data == true) {
                                this.$libs.successAlert(this, {
                                    title: '打款申请提交成功，请在我的订单列表里了解最新状态！',
                                    theme: '提交成功',
                                    enter: '确定',
                                });
                            } else {
                                this.$libs.successAlert(this, {
                                    title: '订单' + response.data.data.join('，') + response.data.message,
                                    theme: '提交失败',
                                    enter: '确定',
                                    type: 'error'
                                });
                            }
                        } else {
                            this.$message.error(response.data.message);
                        }
                    }).catch((error) => {});
            });
        },
        loanApplyException() {
            this.$router.push({ path: '/loanApplyException?orderNo=' + this.orderNo + '&annexBatchNo=' + this.annexBatchNo + '&bizType=' + (this.$refs.carAndCredit ? this.$refs.carAndCredit[0].creditInfo.type : '') });
        },
        dialogLoanClose() {
            this.dialogVisibleVaild = false;
            this.dialogVisibleLoan = false;
        },
        changeLoanMajorPerson() {
            // 互换主贷人
            this.$http.post('/modification/buyerReplacement/' + this.orderNo, {
                reason: this.changeLoanRusult
            }).then((data) => {
                if (data.data.success) {
                    this.dialogVisibleLoan = false;
                    this.$confirm('申请提交成功！', '提交成功', {
                        confirmButtonText: '返回订单处理',
                        cancelButtonText: '关闭',
                        type: 'success'
                    }).then(() => {
                        this.dialogVisibleLoan = false;
                        this.isChange = 0;
                        this.$router.push({ path: '/order' });
                    }).catch(() => {
                        this.dialogVisibleLoan = false;
                    });
                } else {
                    this.$message.error(data.data.message);
                }
            }).catch((error) => {

            });
        },
        change() {
            // 修改
            this.isChange = 1;
            this.activeName = 'tap0';
            let isAttach = false;
            for (var i = 0; i < this.tapList.length; i++) {
                this.$refs[this.tapList[i].temp][0].isEdit = true;
                if (this.tapList[i].index == 5) {
                    isAttach = true;
                    this.$refs[this.tapList[i].temp][0].postDeal(this.orderNo, this.annexBatchNo);
                }
            }
            if (!isAttach) {
                this.tapList.push({ name: '附件', index: 5, temp: 'attachment', show: true });
                this.$nextTick(() => {
                    this.$refs.attachment[0].isEdit = true;
                    this.getDataSecond();
                });
            }
        },
        creditEdit() {
            // 征信修改
            this.isChange = 2;
            this.activeName = 'tap0';
            this.$refs.customInfo[0].isEdit = false;
            this.$refs.credit[0].isEdit = true;
        },
        cancalInfo() {
            // 资料修改的取消
            for (var i = 0; i < this.tapList.length; i++) {
                this.$refs[this.tapList[i].temp][0].isEdit = false;
            }
            this.isChange = 0;
            this.isFirstSubmit2 = true;
        },
        submitInfo() {
            let saveNum = 0;
            for (var i = 1; i < 5; i++) {
                if (this.$refs.credit[0].$refs['carBuyCommon' + i]) {
                    saveNum += this.$refs.credit[0].$refs['carBuyCommon' + i][0].fileListSave;
                }
            }
            if ((this.$refs.credit[0].carBuy.marry == 1 || this.$refs.credit[0].carBuy.marry == 0) && (this.$refs.credit[0].carBuy.marry == 0 || this.$refs.credit[0].carBuy.marry == 1) && (!this.$refs.credit[0].carBuyCommon.name || !this.$refs.credit[0].carBuyCommon.code)) {
                this.$message.error('请补充完整共同购车人信息！');
                return;
            }
            let carBuyCommonImgNum = 0;
            if ((this.$refs.credit[0].carBuy.marry == 1 || this.$refs.credit[0].carBuy.marry == 0) && this.$refs.credit[0].$refs.carBuyCommon.fileList.length < 3) {
                for (let i = 1; i < 5; i++) {
                    if (this.$refs.credit[0].$refs['carBuyCommon' + i]) {
                        let vm = this.$refs.credit[0].$refs['carBuyCommon' + i][0];
                        if (vm.fileListSave == 1) {
                            carBuyCommonImgNum++;
                        }
                    }
                }
                if (carBuyCommonImgNum < 3) {
                    this.$message.error('请补充完整共同购车人图片资料信息！');
                    return;
                }
            }
            if ((this.$refs.credit[0].carBuy.marry == 1 || this.$refs.credit[0].carBuy.marry == 0) && !this.$libs.IdentityCodeValid(this.$refs.credit[0].carBuyCommon.code)) {
                this.$message.error('共同购车人身份证格式验校失败！');
                return;
            }
            if ((this.$refs.credit[0].carBuy.marry == 1 || this.$refs.credit[0].carBuy.marry == 0) && this.$refs.credit[0].carBuyCommon.code == this.$refs.credit[0].carBuy.code) {
                this.$message.error('共同购车人身份证号不能与购车人身份证号相同！');
                return;
            }
            let assurePersonsCodeArr = [];
            if (this.$refs.credit[0].assurePersons) {
                for (let i = 0; i < this.$refs.credit[0].assurePersons.length; i++) {
                    let vm = this.$refs.credit[0].assurePersons[i];
                    if (!this.$libs.IdentityCodeValid(vm.code)) {
                        this.$message.error('担保人身份证格式验校失败！');
                        return;
                    }
                    if (vm.code == this.$refs.credit[0].carBuy.code) {
                        this.$message.error('担保人身份证号不能与购车人身份证号相同！');
                        return;
                    }
                    if (vm.code == this.$refs.credit[0].carBuyCommon.code) {
                        this.$message.error('担保人身份证号不能与共同购车人身份证号相同！');
                        return;
                    }
                    if (assurePersonsCodeArr.join(',').indexOf(vm.code) != -1) {
                        this.$message.error('担保人身份证号不能重复！');
                        return;
                    }
                    assurePersonsCodeArr.push(vm.code);
                }
            }

            if (this.isChange == 1 && (this.$refs.credit[0].carBuy.marry == 1 || this.$refs.credit[0].carBuy.marry == 0 || (this.$refs.credit[0].assurePersons && this.$refs.credit[0].assurePersons.length > 0))) {
                this.isFirstSubmitChangeDialog = true;
                this.$refs.credit[0].creditInfoEnter(this.orderNo, this.isSubmitChangeDialog, this.orderStatus, this.dialogEnterChange());
            } else {
                this.submitInfoEnter();
            }
        },
        submitInfoEnter() {
            this.$store.commit('toSubmitFalse');
            this.isFirstSubmit2 = false;
            // 资料修改的提交
            if (this.isChange == 1) {
                // 资料提交
                let saveNumInfo = 0;
                for (let i = 0; i < this.tapList.length; i++) {
                    let el = this.tapList[i];
                    if (el.index == 0 || el.index == 1 || el.index == 2 || el.index == 3 || el.index == 4 || el.index == 5) {
                        saveNumInfo++;
                    }
                }
                let that = this;
                this.$store.commit('saveNumClear', saveNumInfo);
                this.$store.commit('tipChange', {
                    title: '资料修改提交成功！',
                    theme: '提交成功',
                    enter: '知道了',
                    status: 1,
                    cb: () => {
                        that.$router.push({ path: '/order' });
                    }
                });
                for (var i = 0; i < this.tapList.length; i++) {
                    let el = this.tapList[i];
                    this.$refs[el.temp][0].isEdit = false;
                    switch (el.index) {
                        case 0:
                            if (this.isChangeEdit == false) {
                                this.$refs[el.temp][0].creditInfoEnter(this.orderNo, this.isSubmit, this.orderStatus);
                            }
                            break;
                        case 1:
                            this.$refs[el.temp][0].userInfoEnter(this.orderNo, this.isSubmit, this.orderStatus);
                            break;
                        case 2:
                            if (this.$refs.credit[0].carBuy.marry != 1 && this.$refs.credit[0].carBuy.marry != 0) {
                                this.$refs[el.temp][0].infoEnter(this.orderNo, this.isSubmit, this.orderStatus);
                            }
                            break;
                        case 3:
                            if (!this.$refs.credit[0].assurePersons || this.$refs.credit[0].assurePersons.length <= 0) {
                                this.$refs[el.temp][0].infoEnter(this.orderNo, this.isSubmit, this.orderStatus);
                            }
                            break;
                        case 4:
                            this.$refs[el.temp][0].submitInfo(this.orderNo, this.isSubmit, this.orderStatus);
                            break;
                        case 5:
                            this.$refs[el.temp][0].attachmentEnter(this.orderNo, this.isSubmit, this.orderStatus);
                            break;
                        default:
                            break;
                    }
                }
                this.isChange = 0;
                this.isFirstSubmit2 = true;
            } else if (this.isChange == 2) {
                // 征信提交
                this.$store.commit('saveNumClear', 1);
                this.$store.commit('tipChange', {
                    title: '征信资料修改提交成功！',
                    theme: '提交成功',
                    enter: '知道了',
                });
                this.$refs.credit[0].creditInfoEnter(this.orderNo);
                this.$refs.credit[0].isEdit = false;
                this.isChange = 0;
                this.isFirstSubmit2 = true;
            }
        },
        dialogEnterChange() {
            for (let i = 0; i < this.tapListChangeDialog.length; i++) {
                if (this.tapListChangeDialog[i].index == 2) {
                    if (this.$refs.credit[0].carBuy.marry == 1 || this.$refs.credit[0].carBuy.marry == 0) {
                        this.tapListChangeDialog[i].show = true;
                    } else {
                        this.tapListChangeDialog[i].show = false;
                        this.activeNameChangeDialog = 'tap3';
                    }
                } else if (this.tapListChangeDialog[i].index == 3) {
                    if (this.$refs.credit[0].assurePersons && this.$refs.credit[0].assurePersons.length > 0) {
                        this.tapListChangeDialog[i].show = true;
                    } else {
                        this.tapListChangeDialog[i].show = false;
                        this.activeNameChangeDialog = 'tap2';
                    }
                }
                if (this.tapListChangeDialog[i].show == false) {
                    this.tapListChangeDialog = this.tapListChangeDialog.filter(tab => tab.index != this.tapListChangeDialog[i].index);
                    i--;
                }
            }
            this.isChangeEdit = true;
            this.$nextTick(() => {
                console.log('refs');
                console.log(this.$refs);
                for (let i = 0; i < this.tapListChangeDialog.length; i++) {
                    let el = this.tapListChangeDialog[i];
                    this.$refs[el.temp + 'ChangeDialog'][0].isEdit = true;
                    switch (el.index) {
                        case 2:
                            this.$refs[el.temp + 'ChangeDialog'][0].getInfo(this.orderNo, this.isSubmitChangeDialog);
                            break;
                        case 3:
                            this.$refs[el.temp + 'ChangeDialog'][0].getInfo(this.orderNo, this.isSubmitChangeDialog);
                            break;
                        default:
                            break;
                    }
                }
            });
        },
        savesChangeDialog() {
            this.isSubmitChangeDialog = false;
            this.$store.commit('clearStatus');
            this.$store.commit('tipChange', {
                title: '修改资料保存成功！',
                theme: '保存成功',
                enter: '知道了',
            });
            this.saveChangeDialog();
        },
        saveChangeDialog() {
            this.$store.commit('saveNumClear', this.tapListChangeDialog.length);
            for (var i = 0; i < this.tapListChangeDialog.length; i++) {
                let el = this.tapListChangeDialog[i];
                switch (el.index) {
                    case 2:
                        this.$refs[el.temp + 'ChangeDialog'][0].infoEnter(this.orderNo, this.isSubmitChangeDialog, this.orderStatus, () => {
                            this.isFirstSubmitChangeDialog = true;
                        });
                        break;
                    case 3:
                        this.$refs[el.temp + 'ChangeDialog'][0].infoEnter(this.orderNo, this.isSubmitChangeDialog, this.orderStatus, () => {
                            this.isFirstSubmitChangeDialog = true;
                        });
                        break;
                    default:
                        break;
                }
            }
        },
        submitChangeDialog() {
            this.isFirstSubmitChangeDialog = false;
            this.$store.commit('clearStatus');
            this.isSubmitChangeDialog = true;
            this.$store.commit('toSubmitFalse');
            this.$store.commit('tipChange', {
                title: '修改资料提交成功！',
                theme: '提交成功',
                enter: '知道了',
                status: 1,
                cb: this.submitInfoEnter()
            });
            this.saveChangeDialog();
        },
        recall() {
            // 撤回
            this.$confirm('是否确认撤回?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$http.post('/submitTaskController/salesManRevokeTask', {
                        "orderNo": this.orderNo,
                    })
                    .then((response) => {
                        if (response.data.success) {
                            this.$message({
                                type: 'success',
                                message: '撤回成功!'
                            });
                            this.$router.push({ path: '/order' });
                        } else {
                            this.$message.error('撤回失败！');
                        }
                    });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消撤回'
                });
            });
        },
        invalid() {
            // 作废
            if (this.invalidRusult == '') {
                this.$message.error('请选择作废原因！');
                return;
            }
            this.$http.post('/submitTaskController/invalidApply', {
                orderNo: this.orderNo,
                remark: this.invalidRusult
            }).then((data) => {
                if (data.data.success) {
                    this.dialogVisibleVaild = false;
                    this.$message({
                        message: '作废成功！',
                        type: 'success'
                    });
                } else {
                    this.$message.error(data.data.message);
                }
            }).catch((error) => {

            });

        },
        loanApplyEnter() {
            for (let i = 0; i < this.tapListDialog.length; i++) {
                if (this.tapListDialog[i].show == false) {
                    this.tapListDialog = this.tapListDialog.filter(tab => tab.index != this.tapListDialog[i].index);
                    i--;
                }
            }
            this.isEdit = true;
            this.$nextTick(() => {
                console.log('refs');
                console.log(this.$refs);
                let ishaveAttach = false;
                for (var i = 0; i < this.tapListDialog.length; i++) {
                    let el = this.tapListDialog[i];
                    // this.$refs[el.temp + 'Dialog'][0].disabled = false;
                    this.$refs[el.temp + 'Dialog'][0].isEdit = true;
                    if (el.index == 3) {
                        ishaveAttach = true;
                    }
                    switch (el.index) {
                        case 1:
                            this.$refs[el.temp + 'Dialog'][0].getUserInfo(this.orderNo, this.isSubmit);
                            break;
                        case 2:
                            this.$refs[el.temp + 'Dialog'][0].getInfo(this.orderNo, this.isSubmit);
                            break;
                        case 3:
                            this.$refs[el.temp + 'Dialog'][0].getInfo(this.orderNo, this.isSubmit);
                            break;
                        case 4:
                            this.$refs[el.temp + 'Dialog'][0].isGps = false;
                            this.$refs[el.temp + 'Dialog'][0].getCarInfo(this.orderNo, this.isSubmit);
                            this.$refs[el.temp + 'Dialog'][0].getLoanInfo(this.orderNo, this.isSubmit);
                            break;
                        case 5:
                            this.$refs[el.temp + 'Dialog'][0].postDeal(this.orderNo, this.annexBatchNo);
                            break;
                        default:
                            break;
                    }
                }
                if (!ishaveAttach) {
                    this.$refs['attachmentDialog'][0].isShow.assurePerson = 'none';
                }
            });
        },
        saves() {
            this.isSubmit = false;
            this.$store.commit('clearStatus');
            this.$store.commit('tipChange', {
                title: '贷款申请资料保存成功！',
                theme: '保存成功',
                enter: '知道了',
                cb: () => {
                    this.isEdit = false;
                    this.getDataSecond();
                }
            });
            this.save();
        },
        save() {
            this.$store.commit('saveNumClear', this.tapListDialog.length);
            for (var i = 0; i < this.tapListDialog.length; i++) {
                let el = this.tapListDialog[i];
                switch (el.index) {
                    case 1:
                        this.$refs[el.temp + 'Dialog'][0].userInfoEnter(this.orderNo, this.isSubmit, this.orderStatus, () => {
                            this.isFirstSubmit = true;
                        });
                        break;
                    case 2:
                        this.$refs[el.temp + 'Dialog'][0].infoEnter(this.orderNo, this.isSubmit, this.orderStatus, () => {
                            this.isFirstSubmit = true;
                        });
                        break;
                    case 3:
                        this.$refs[el.temp + 'Dialog'][0].infoEnter(this.orderNo, this.isSubmit, this.orderStatus, () => {
                            this.isFirstSubmit = true;
                        });
                        break;
                    case 4:
                        this.$refs[el.temp + 'Dialog'][0].submitInfo(this.orderNo, this.isSubmit, this.orderStatus, () => {
                            this.isFirstSubmit = true;
                        });
                        break;
                    case 5:
                        this.$refs[el.temp + 'Dialog'][0].attachmentEnter(this.orderNo, this.isSubmit, this.orderStatus);
                        break;
                    default:
                        break;
                }
            }
        },
        submit() {
            this.isFirstSubmit = false;
            this.$store.commit('clearStatus');
            this.isSubmit = true;
            this.$store.commit('toSubmit');
            this.$store.commit('tipChange', {
                title: '贷款申请资料提交成功！',
                theme: '提交成功',
                enter: '知道了'
            });
            this.save();
        },
        getDataSecond() {
            for (let i = 0; i < this.tapList.length; i++) {
                let el = this.tapList[i];
                switch (el.index) {
                    case 6:
                        this.$refs[el.temp][0].customerIdCard = this.customerIdCard;
                        this.$refs[el.temp][0].getDate(this.orderNo);
                        break;
                    case 1:
                        this.$refs[el.temp][0].getUserInfo(this.orderNo, this.isSubmit);
                        break;
                    case 2:
                        this.$refs[el.temp][0].getInfo(this.orderNo, this.isSubmit);
                        break;
                    case 3:
                        this.$refs[el.temp][0].getInfo(this.orderNo, this.isSubmit);
                        break;
                    case 4:
                        this.$refs[el.temp][0].isGps = false;
                        this.$refs[el.temp][0].getCarInfo(this.orderNo, this.isSubmit);
                        this.$refs[el.temp][0].getLoanInfo(this.orderNo, this.isSubmit);
                        break;
                    case 5:
                        this.$refs[el.temp][0].postDeal(this.orderNo, this.annexBatchNo);
                        break;
                    case 10:
                        this.$refs[el.temp][0].getInfo(this.orderNo);
                        break;
                    default:
                        break;
                }
            }
        },
        attachHave() {
            let ishaveAttach = false;
            for (var i = 0; i < this.tapList.length; i++) {
                if (this.tapList[i].index == 5) {
                    ishaveAttach = true;
                    this.tapList[i].show = true;
                }
            }
            if (!ishaveAttach) {
                this.tapList.push({ name: '附件', index: 5, temp: 'attachment', show: true });
            }
            this.isAttachHaveRun = true;
        },
    },
    mounted() {
        if (this.$route.query.isShowDialog == '1') {
            this.loanApplyEnter()
            this.isEdit = true
        }
        this.$refs.attachment[0].postDeal(this.orderNo, this.annexBatchNo);
        this.$refs.attachment[0].show = false;
        this.$http.get('/submitTaskController/isAllowToAccomApply/' + this.orderNo).then((data) => {
            if (data.data.success) {
                if (data.data.data == true) {
                    // 显示通融
                    this.isTrShow = true;
                } else {
                    this.isTrShow = false;
                }
            }
        }).catch((error) => {

        });
        this.$refs.steps.getCheckInfo(this.orderNo, this.orderStatus);
        this.$refs.carAndCredit[0].isGps = false;
        this.tapNumEdit = 0;
        this.$refs.credit[0].getCreditInfo(this.orderNo, {
            carBuyCommon: () => {
                this.isChangeLoanShow = true;
                this.tapNumEdit++;
                console.log('tapList1');
            },
            assurePerson: () => {
                this.tapNumEdit++;
                console.log('tapList2');
            },
            carBuyCommonNone: () => {
                this.isChangeLoanShow = false;
                for (let i = 0; i < this.tapList.length; i++) {
                    let val = this.tapList[i];
                    if (val.index == 2) {
                        val.show = false;
                        console.log('tapList1');
                        this.tapNumEdit++;
                    }
                }
                for (let i = 0; i < this.tapListDialog.length; i++) {
                    let val = this.tapListDialog[i];
                    if (val.index == 2) {
                        val.show = false;
                    }
                }
            },
            assurePersonNone: () => {
                for (let i = 0; i < this.tapList.length; i++) {
                    let val = this.tapList[i];
                    if (val.index == 3) {
                        val.show = false;
                        console.log('tapList2');
                        this.tapNumEdit++;
                    }
                }
                for (let i = 0; i < this.tapListDialog.length; i++) {
                    let val = this.tapListDialog[i];
                    if (val.index == 3) {
                        val.show = false;
                    }
                }
            }
        });
        this.$refs.historyLoan[0].customerIdCard = this.customerIdCard;
        this.$refs.historyLoan[0].getDate(this.orderNo, () => {
            for (let i = 0; i < this.tapList.length; i++) {
                let val = this.tapList[i];
                if (val.index == 6) {
                    val.show = false;
                    console.log('tapList3');
                    this.tapNumEdit++;
                }
            }
            for (let i = 0; i < this.tapListDialog.length; i++) {
                let val = this.tapListDialog[i];
                if (val.index == 6) {
                    val.show = false;
                }
            }
        }, () => {
            console.log('tapList31');
            this.tapNumEdit++;
        });
        if (this.orderStatus == 10) {
            this.isTip = true;
        }
    }
}

</script>
<style lang="scss" scoped>
@import '../../assets/css/site.scss';
.loanApplyDeal {
    padding: 10px 16px;
    position: relative;
    .info-content {
        background: #fff;
        padding: 20px;
        position: absolute;
        top: 50px;
        left: 16px;
        right: 16px;
        bottom: 0;
        .info-temp {
            background: #fff;
            padding: 0px 20px 150px 20px;
            .credit,
            .customInfo,
            .carBuyCommon,
            .assurePerson,
            .carAndCredit,
            .attachment,
            {
                padding-right: 200px;
            }
        }
    }
    .footer-content {
        background: #fff;
        position: fixed;
        bottom: 0;
        left: 200px;
        right: 0px;
        height: 36px;
        padding: 12px 100px 12px 50px;
        z-index: 1;
        .cancel {
            color: #99A9BF;
        }
    }
    .dialog-edit {
        // position: absolute;
        hr {
            margin: 0px 0px 0px 0px;
            border: none;
            border-bottom: 1px solid #d3dce6;
        }
        .info-temp {
            background: #fff;
            .customInfo,
            .carBuyCommon,
            .assurePerson,
            .attachment,
            {
                padding-right: 15px;
            }
            .carAndCredit {
                padding-right: 55px;
            }
        }
        .info-tabs {
            min-height: 520px;
            margin: 30px 113px 0px 113px;
        }
        .dialog-footer {
            text-align: center;
            padding-top: 10px;
            border-top: 1px solid #d3dce6;
            .tip {
                font-size: 12px;
                color: #ff4949;
                position: absolute;
                margin-left: 10px;
                line-height: 2.8;
            }
        }
    }
    .gpsAddDialog {
        padding: 0 150px;
        max-height: 500px;
        overflow: auto;
    }


    .dialogContent {
        padding: 0px 30px 10px 30px;
        .radio {
            margin: 3px 0px;
        }
        .dialog-footer {
            border-top: 1px solid #000;
        }
    }
}

</style>
